var urls = "http://localhost:8080/data";
var argArr = Array();
var app = getApp();

var tempFilePaths;
var util = require("../../utils/util.js");

var upload = require("upload.js");
Page({
    data: {
        files: []
    },
    chooseImage: function (e) {
        var that = this;
        wx.chooseImage({
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
              // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片          var tempFilePaths = res.tempFilePaths
              tempFilePaths = res.tempFilePaths;
              console.log(tempFilePaths);
                that.setData({
                    files: that.data.files.concat(res.tempFilePaths)
                });
            }
        })
    },

    previewImage: function(e){
        wx.previewImage({
            current: e.currentTarget.id, // 当前显示图片的http链接
            urls: this.data.files // 需要预览的图片http链接列表
        })
    },

    formSubmit: function (e) {
      var that = this;


      var formDatas = e.detail.value; //获取表单所有input的值  
      url: urls + "/returnRoom", //仅为示例，非真实的接口地址
      console.log(formDatas);
      console.log(tempFilePaths);


        var pics = this.data.files;
        upload.uploadimg({
          url: urls + "/returnRoom",//这里是你图片上传的接口
          path: pics,//这里是选取的图片的地址数组
          formData:formDatas,
        });
      

      /*wx.uploadFile({
        url: urls + "/returnRoom", //仅为示例，非真实的接口地址
        filePath: that.data.files[i],
        name: 'file',
        formData:formDatas,
        success: function (res) {
          var data = res.data
          //do something
          console.log(res);
        },

      })*/
    },  

    onLoad:function(){
      wx.startPullDownRefresh();
    },
    onPullDownRefresh: function () {

      wx.showLoading({
        title: '加载中',
      })
      // wx.stopPullDownRefresh();
      argArr.temp = this;
      argArr.app = app;
      util.judgeLink(argArr);
    }
    

    
});

